﻿
$(document).ready(function () {
    $("table[id^=ctl00_ContentPlaceHolder3_wgt_]").each(function () {
        if ($(this).attr('id').indexOf('_table') > -1)// by sanal on Jul 04, 2012 to make the widget UI better
        {
            $(this).attr('cellpadding', '0');
            $(this).attr('cellspacing', '0');
        }
    });
    handleDashboardChartSize("ctl00_ContentPlaceHolder3_wgt_", "ctl00xContentPlaceHolder3xwgtx", false); // Added by 'Imran Gani' on 13-Aug-2014, for Dashboard widget property
});
function UpdateEvent() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered").value = "1";
    }
}
function UpdateOtherEvent() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered") != null) {
        document.getElementById("ctl00_ContentPlaceHolder3_hfEventTriggered").value = "0";
    }
}

function showHideTooltipDIVDashboard(imageid) {
    if (document.getElementById("page_tooltip_div").style.display == "none") {
        document.getElementById("page_tooltip_div").style.display = "block";
        //document.getElementById("page_tooltip_img").src = "Images/collapse3.gif";
        document.getElementById(imageid).src = "Images/collapse3.gif";
    }
    else {
        document.getElementById("page_tooltip_div").style.display = "none";
        //document.getElementById("page_tooltip_img").src = "Images/expand3.gif";
        document.getElementById(imageid).src = "Images/expand3.gif";
    }
}
function GetBindValue(bind_id, hiddenfield, textboxid) {
    try {
        if (document.getElementById(hiddenfield) != null) {
            if (document.getElementById(textboxid) != null) {
                var SearchText = document.getElementById(textboxid).value;
                var xmlHttp_fb;
                try {
                    xmlHttp_fb = new XMLHttpRequest();
                }
                catch (e) {
                    try {
                        xmlHttp_fb = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e) {
                        try {
                            xmlHttp_fb = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {
                            return false;
                        }
                    }
                }
                xmlHttp_fb.onreadystatechange = function () {
                    if (xmlHttp_fb.readyState == 1) {
                        //document.getElementById("ctl00_fb_status").innerHTML = "<img src='Images/load.gif' border='0'></img>&nbsp;Submitting...";
                    }
                    if (xmlHttp_fb.readyState == 4) {
                        //if (xmlHttp_fb.responseText!="")
                        //{
                        var SearchValue = xmlHttp_fb.responseText;
                        document.getElementById(hiddenfield).value = SearchValue;

                        //}
                    }
                }
                xmlHttp_fb.open("GET", "LoadTips.aspx?PB=1&bnd=" + bind_id + "&SD=" + SearchText + "", true);
                xmlHttp_fb.send(null);
            }
        }
        //    xmlHttp_fb.open("GET","loadTips.aspx?fb=" + escape(fb)+"&IsMail=false&EMid="+emailid+"",true);
    }
    catch (Exxx) {

    }
}
// Added by 'Imran Gani' on 07-Aug-2014, for Dashboard widget property
function showWidgetProperties() {
    try {
        document.getElementById("ctl00_ContentPlaceHolder3_lblmessage").innerText = "";

        var lstbox = document.getElementById("ctl00_ContentPlaceHolder3_lstSelectedDashboards");
        if (lstbox == null)
            return false;
        if (lstbox.options.length == 0)
            return false;
        var idx = lstbox.options.selectedIndex;
        if (idx == -1) return false;

        $("#td_wdgSettings").css("visibility", "visible");
        var jsondata = document.getElementById("ctl00_ContentPlaceHolder3_hfJsonWdgSettings").value;
        if (jsondata != "") {
            var objdata = jQuery.parseJSON(jsondata);
            if (objdata != null) {
                for (var j = 0; j < objdata.jsondata.length; j++) {
                    if (objdata.jsondata[j].widget == lstbox.options[idx].value) {
                        document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked = (objdata.jsondata[j].fullview.toString().toLowerCase() == "true" ? true : false);
                        document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked = (objdata.jsondata[j].newsection.toString().toLowerCase() == "true" ? true : false);
                        $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val(objdata.jsondata[j].widget_size.toString().toLowerCase());
                        break;
                    }
                    document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked = false;
                    document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked = false;
                    $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val("");
                }
            }
        }
    } catch (err) {
        document.getElementById("ctl00_ContentPlaceHolder3_lblmessage").innerHTML = err.Description;
    }
    return false;
}

function applyWidgetProperties() {
    try {

        var lstbox = document.getElementById("ctl00_ContentPlaceHolder3_lstSelectedDashboards");
        if (lstbox == null)
            return false;
        if (lstbox.options.length == 0)
            return false;
        var idx = lstbox.options.selectedIndex;
        if (idx == -1) return false;

        var isNewWidgetSettings = true;
        var jsondata = document.getElementById("ctl00_ContentPlaceHolder3_hfJsonWdgSettings").value;
        if (jsondata != "") {
            var objdata = jQuery.parseJSON(jsondata);
            if (objdata != null) {
                for (var j = 0; j < objdata.jsondata.length; j++) {
                    if (objdata.jsondata[j].widget == lstbox.options[idx].value) {
                        objdata.jsondata[j].fullview = document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked;
                        objdata.jsondata[j].newsection = document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked;
                        objdata.jsondata[j].widget_size = $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val();
                        isNewWidgetSettings = false;
                        break;
                    }
                }
                if (isNewWidgetSettings)
                    objdata.jsondata.push({ "widget": lstbox.options[idx].value, "fullview": document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked, "newsection": document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked, "widget_size": $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val() });
                document.getElementById("ctl00_ContentPlaceHolder3_hfJsonWdgSettings").value = JSON.stringify(objdata);
            }
            else {
                document.getElementById("ctl00_ContentPlaceHolder3_hfJsonWdgSettings").value = "{\"jsondata\":[{" + "\"widget\" : \"" + lstbox.options[idx].value + "\", \"fullview\" : " + document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked + ", \"newsection\" : " + document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked + ", \"widget_size\" : \"" + $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val() + "\"}]}";
            }
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder3_hfJsonWdgSettings").value = "{\"jsondata\":[{" + "\"widget\" : \"" + lstbox.options[idx].value + "\", \"fullview\" : " + document.getElementById("ctl00_ContentPlaceHolder3_chkFullView").checked + ", \"newsection\" : " + document.getElementById("ctl00_ContentPlaceHolder3_chkNewSection").checked + ", \"widget_size\" : \"" + $("#ctl00_ContentPlaceHolder3_ddlWidgetSize").val() + "\"}]}";
        }
    } catch (err) {
        document.getElementById("ctl00_ContentPlaceHolder3_lblmessage").innerHTML = err.Description;
    }
    return false;
}
